<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_blank
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Send to friend form
 *
 * @see Mage_Sendfriend_Block_Index
 */
?>
<script type="text/javascript">
//<![CDATA[
    i=0;
    var recipCount  = 1;
    var maxRecip    = <?php echo $this->getMaxRecipients() ?>;
    function remove_recipient(i){
        $('recipients_name'+i).up(2).remove();
        recipCount--;
        if(recipCount<maxRecip && maxRecip != 0) {
            $('add_recipient_button').show();
            $('max_recipient_message').hide();
        }
        return false;
    }

    function add_recipient(){
        ul = $('recipients_options');
        var li_mail = Element.extend(document.createElement("LI"));
        li_mail.addClassName('add-row');
        li_mail.innerHTML = '<a href="delete_email" onclick="remove_recipient('+i+'); return false" class="btn-remove"><img src="<?php echo $this->getSkinUrl('images/list_remove_btn.gif') ?>" alt="<?php echo $this->__('Remove Email') ?>" title="<?php echo $this->__('Remove Email') ?>" /><\/a>'
        li_mail.innerHTML += '<div class="input-box"><label for="recipients_name"><?php echo $this->__('Name:') ?> <span class="required">*<\/span><\/label><br /><div><input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name'+i+'" /><\/div>';
        li_mail.innerHTML += '<div class="input-box"><label for="recipients_email"><?php echo $this->__('Email Address:') ?><span class="required">*<\/span><\/label><br /><input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email'+i+'" type="text" class="input-text required-entry validate-email" /><\/div>';
        i++;
        recipCount++;
        if(recipCount>=maxRecip && maxRecip != 0) {
            $('add_recipient_button').hide();
            $('max_recipient_message').show();
        }

        ul.appendChild(li_mail);
    }
//]]>
</script>

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title">
    <h2><?php echo $this->__('Email to a Friend') ?></h2>
</div>
<form action="<?php echo $this->getUrl('*/*/sendmail', array('id'=>$this->getProductId(), 'cat_id'=>$this->getCategoryId())) ?>" method="post" id="product_sendtofriend_form">
    <fieldset class="group-select">
        <h3><?php echo $this->__('Sender:') ?></h3>
         <ul class="form-list" id="sender_options">
               <li>
                    <div class="input-box">
                        <label for="sender_name"><?php echo $this->__('Name:') ?> <span class="required">*</span></label><br />
                        <input name="sender[name]" value="<?php echo $this->htmlEscape($this->getUserName()) ?>" title="<?php echo $this->__('Name') ?>" id="sender_name" type="text" class="input-text required-entry" />
                    </div>
                    <div class="input-box">
                       <label for="sender_email"><?php echo $this->__('Email:') ?> <span class="required">*</span></label><br />
                       <input name="sender[email]" value="<?php echo $this->htmlEscape($this->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" id="sender_email" type="text" class="input-text required-entry validate-email" /></div>
                </li>
                <li>
                    <label for="sender_message"><?php echo $this->__('Message:') ?></label><br />
                    <textarea name="sender[message]" id="sender_message" cols="3" rows="3" style="height:100px;"><?php echo $this->htmlEscape($this->getFormData()->getData('sender/message'))?></textarea>
                </li>

         </ul>
    </fieldset>

    <fieldset class="group-select">
        <h3><?php echo $this->__('Recipient:') ?></h3>
            <ul class="form-list" id="recipients_options">
                    <li>
                        <div class="input-box">
                            <label for="recipients_name"><?php echo $this->__('Name:') ?> <span class="required">*</span></label><br />
                            <input name="recipients[name][]" type="text" class="input-text required-entry" id="recipients_name" />
                        </div>
                        <div class="input-box">
                            <label for="recipients_email"><?php echo $this->__('Email Address:') ?> <span class="required">*</span></label><br />
                            <input name="recipients[email][]" value="" title="<?php echo $this->__('Email Address') ?>" id="recipients_email" type="text" class="input-text required-entry validate-email" />
                        </div>
                    </li>
            </ul>
    <div id="max_recipient_message" style="display:none;">
    <?php if ($this->getMaxRecipients()): ?>
      <p><?php echo $this->__('Maximum %d email addresses allowed.', $this->getMaxRecipients()) ?></p>
    <?php endif; ?>
    </div>
    <?php if (1 < $this->getMaxRecipients()): ?>
    <p id="add_recipient_button">
        <button class="button" onclick="add_recipient();" type="button"><span><?php echo $this->__('Add Recipient') ?></span></button>
    </p>
    <?php endif; ?>
    </fieldset>
    <div class="buttons-set">
        <button type="submit" class="button"><span><?php echo $this->__('Send email') ?></span></button>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var productSendtofriendForm = new VarienForm('product_sendtofriend_form');
    productSendtofriendForm.submit = function() {
        if(this.validator.validate()) {
            this.form.submit();
        }
    }.bind(productSendtofriendForm);
//]]>
</script>
